home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / SYS_TOOL / CALL32NT / TPW-BPW / TESTW95.PAS < prev   
Pascal/Delphi Source File  |  1995-06-27  |  4KB  |  108 lines

  1. program TestW95;    {Shows the directory of c:\ with long filenames in Win95/WinNT}
  2.                     {Written in Turbo Pascal for Windows 1.5      }
  3.                     {By Christian Ghisler, CIS: 100332,1175       }
  4.                     {Released to the public domain on June 14,1995}
  5.  
  6. uses wintypes,
  7.      winprocs,
  8.      Wincrt,
  9.      call32nt;
  10.  
  11. type
  12.   ttime=array[0..1] of longint;
  13.   fd=record
  14.     dwFileAttributes:longint;
  15.     ftCreationTime,
  16.     ftLastAccessTime,
  17.     ftLastWriteTime:ttime;
  18.     nFileSizeHigh,
  19.     nFileSizeLow,
  20.     dwReserved0,
  21.     dwReserved1:longint;
  22.     cFileName:array[0..259] of char;
  23.     cAlternateFileName:array[0..13] of char;
  24.   end;
  25.   pfd=^fd;
  26.  
  27.   tSYSTEMTIME=record
  28.     wYear,
  29.     wMonth,
  30.     wDayOfWeek,
  31.     wDay,
  32.     wHour,
  33.     wMinute,
  34.     wSecond,
  35.     wMilliseconds:WORD;
  36.   end;
  37.  
  38. {Declaration of the 32 bit functions}
  39. {W32 is put in front of the name to distinguish from 16 bit functions}
  40. {This is not necessary, the functions can have ANY name}
  41. var
  42.  W32FindFirstFile:function(lpszSearchFile:pchar;var lpffd:fd;id:longint):longint;
  43.  W32FindNextFile:function(hFindFile:longint;var lpffd:fd;id:longint):longbool;
  44.  W32FindClose:function(hFindFile:longint;id:longint):Longbool;
  45.  W32FileTimeToSystemTime:function(var lpft:ttime;var lpst:tsystemtime;id:longint):longbool;
  46.  W32FileTimeToLocalFileTime:function(var lpft,lpftlocal:ttime;id:longint):longbool;
  47.  
  48. {Declaration of a unique identifier for each 32 bit function}
  49. var
  50.   id_W32FindFirstFile,
  51.   id_W32FindNextFile,
  52.   id_W32FindClose,
  53.   id_W32FileTimeToSystemTime,
  54.   id_W32FileTimeToLocalFileTime:longint;
  55.   lr:fd;
  56.   handle:longint;
  57.   localtime:ttime;
  58.   ok:longbool;
  59.   i:integer;
  60.   tdt:tsystemtime;
  61.  
  62. begin
  63.   screensize.y:=100;
  64.   writeln('Test of Win32 functions from Win16!');
  65.  
  66.   {Initialization of the 32 bit functions}
  67.   @W32FindFirstFile:=@Call32;
  68.   @W32FindNextFile:=@Call32;
  69.   @W32FindClose:=@Call32;
  70.   @W32FileTimeToSystemTime:=@Call32;
  71.   @W32FileTimeToLocalFileTime:=@Call32;
  72.  
  73.   {Each function must be declared with Declare32. The handle returned by Declare32
  74.    must be passed as the last parameter of the function when the function is called}
  75.   {Parameters of Declare32: }
  76.   {First:  The name of the original win32 function: CASE SENSITIVE!!!!!}
  77.   {Second: The name of the 32 bit module where the function is located}
  78.   {Third:  A string describing all parameters. p=pointer, i=longint, w=Windows handle}
  79.  
  80.   id_W32FindFirstFile:=Declare32('FindFirstFile', 'kernel32', 'pp');
  81.   id_W32FindNextFile:=Declare32('FindNextFile', 'kernel32', 'ip');
  82.   id_W32FindClose:=Declare32('FindClose', 'kernel32', 'i');
  83.   id_W32FileTimeToSystemTime:=Declare32('FileTimeToSystemTime', 'kernel32', 'pp');
  84.   id_W32FileTimeToLocalFileTime:=Declare32('FileTimeToLocalFileTime', 'kernel32', 'pp');
  85.  
  86.   {Check if everything went well. If there was only a single error, Call32NTError=false}
  87.   if Call32NTError then begin
  88.     writeln('Sorry, cannot load the desired 32 bit functions!');
  89.     halt(1);
  90.   end;
  91.  
  92.   {Initialization is done, here comes the code which actually uses the functions}
  93.  
  94.   writeln('Directory of c:\');
  95.   handle:=W32FindFirstFile('c:\*.*',lr,id_W32FindFirstFile);
  96.   if handle<>-1 then repeat
  97.     write(lr.cfilename);
  98.     W32FileTimeToLocalFileTime(lr.ftLastWriteTime,localtime,id_W32FileTimeToLocalFileTime);
  99.     W32FileTimeToSystemTime(localtime,tdt,id_W32FileTimeToSystemTime);
  100.     gotoxy(40,wherey);
  101.     writeln(tdt.wmonth,'/',tdt.wday,'/',tdt.wyear,'  ',tdt.whour,':',tdt.wminute,':',tdt.wsecond);
  102.     ok:=W32FindNextFile(handle,lr,id_W32FindNextFile);
  103.   until not ok;
  104.   W32FindClose(handle,id_W32FindClose);
  105.   {No need to un-initialize, the 32-bit libraries are automatically freed when the program terminates}
  106. end.
  107.  
  108.